home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1998 January / PC Answers Issue 49 Cover CD January 1998.iso / Apps / Director / DATA.Z / Widget Wizard.dir / WidgtBehaviors_103_scrollbar.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  3.4 KB  |  102 lines

  1. property extentSprite, thumbheight, travelrange, position, offset, tracking, dynamic, proportional, fieldNum, totalHeight, fieldHeight, fieldMem
  2.  
  3. on getPropertyDescriptionList
  4.   set description to [:]
  5.   addProp(description, #dynamic, [#default: 1, #format: #boolean, #comment: "Dynamic:"])
  6.   addProp(description, #fieldNum, [#default: the currentSpriteNum - 3, #format: #integer, #comment: "Scroll which sprite:"])
  7.   addProp(description, #extentSprite, [#default: the currentSpriteNum - 2, #format: #integer, #comment: "Slider Constraint Sprite:"])
  8.   return description
  9. end
  10.  
  11. on getBehaviorDescription
  12.   return "Vertical Multiline Textfield Scrollbar"
  13. end
  14.  
  15. on beginSprite me
  16.   set fnum to the fieldNum of me
  17.   set fmember to the memberNum of sprite the fieldNum of me
  18.   set the fieldMem of me to fmember
  19.   set viewable to 1.0
  20.   set the totalHeight of me to float(the bottom of the rect of member fmember)
  21.   set the fieldHeight of me to float(the bottom of sprite fnum - the top of sprite fnum)
  22.   set viewable to the fieldHeight of me / the totalHeight of me
  23.   puppetSprite(the spriteNum of me, 1)
  24.   set barheight to the bottom of sprite the extentSprite of me - the top of sprite the extentSprite of me
  25.   set the thumbheight of me to the height of sprite the spriteNum of me
  26.   set the travelrange of me to barheight - thumbheight
  27.   set the tracking of me to 0
  28.   set the position of me to 0.0
  29.   positionThumb(me)
  30. end
  31.  
  32. on getAssocMembers
  33.   set myPropList to []
  34.   return myPropList
  35. end
  36.  
  37. on endSprite me
  38.   puppetSprite(the spriteNum of me, 0)
  39. end
  40.  
  41. on positionThumb me
  42.   set topT to (the position of me * the travelrange of me) + the top of sprite the extentSprite of me
  43.   set snum to the spriteNum of me
  44.   set Trect to rect(the left of sprite snum, topT, the right of sprite snum, topT + the thumbheight of me)
  45.   set the rect of sprite snum to Trect
  46. end
  47.  
  48. on scrollText me
  49.   set the scrollTop of member the fieldMem of me to the position of me * (the totalHeight of me - the fieldHeight of me)
  50. end
  51.  
  52. on prepareFrame me
  53.   if the tracking of me then
  54.     set thumb to the spriteNum of me
  55.     set extent to the extentSprite of me
  56.     set V to the mouseV - the offset of me
  57.     if V < the top of sprite extent then
  58.       set V to the top of sprite extent
  59.     end if
  60.     if V > (the bottom of sprite extent - the thumbheight of me) then
  61.       set V to the bottom of sprite extent - the thumbheight of me
  62.     end if
  63.     set the position of me to float(V - the top of sprite extent) / float(the travelrange of me)
  64.     positionThumb(me)
  65.     if the dynamic of me then
  66.       scrollText(me)
  67.     end if
  68.   end if
  69. end
  70.  
  71. on mouseDown me
  72.   set the tracking of me to 1
  73.   set the offset of me to the mouseV - the top of sprite the spriteNum of me
  74. end
  75.  
  76. on mouseUp me
  77.   if the dynamic of me = 0 then
  78.     scrollText(me)
  79.   end if
  80.   set the tracking of me to 0
  81. end
  82.  
  83. on mouseUpOutSide me
  84.   if the dynamic of me = 0 then
  85.     scrollText(me)
  86.   end if
  87.   set the tracking of me to 0
  88. end
  89.  
  90. on scroll_a_line me, amount
  91.   set the scrollTop of member the fieldMem of me to the position of me * (the totalHeight of me - the fieldHeight of me)
  92.   set change_amount to float(amount) * (float(the textHeight of member the fieldMem of me) / float(the totalHeight of me - the fieldHeight of me))
  93.   set the position of me to the position of me + change_amount
  94.   if the position of me < 0.0 then
  95.     set the position of me to 0.0
  96.   end if
  97.   if the position of me > 1.0 then
  98.     set the position of me to 1.0
  99.   end if
  100.   positionThumb(me)
  101. end
  102.